package com.xiaobai.frame.controller;


import com.xiaobai.common.utils.result.Result;
import com.xiaobai.frame.service.IMenuService;
import com.xiaobai.model.vo.system.menu.MenuAddVO;
import com.xiaobai.model.vo.system.menu.MenuUpdateVO;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-10
 */
@RestController
@RequestMapping("/menu")
@AllArgsConstructor
public class MenuController {

    private final IMenuService iMenuService;


    @GetMapping("tree")
    @Operation(summary = "获取到菜单树")
    public Result getMenuTree(Long id) {
        return iMenuService.getMenuTree(id);
    }


    @PostMapping("add")
    @Operation(summary = "新增菜单数据")
    public Result add(@Validated MenuAddVO menuAddVO) {
        return iMenuService.add(menuAddVO);
    }

    @PostMapping("update")
    @Operation(summary = "修改菜单")
    public Result update(@Validated MenuUpdateVO menuUpdateVO) {
        return iMenuService.update(menuUpdateVO);
    }

    @PostMapping("delete")
    @Operation(summary = "删除数据")
    public Result delete(List<Long> ids) {
        return iMenuService.delete(ids);
    }

    @GetMapping("get")
    @Operation(summary = "查询单个数据的详细信息")
    public Result get(@Validated @NotNull(message = "id不能为空") Long id) {
        return iMenuService.get(id);
    }

    @GetMapping("role-menu")
    @Operation(summary = "通过对应的角色查询到对应的权限")
    public Result getRoleMenu(Long role) {
        return iMenuService.getRoleMenu(role);
    }



}
